<!-- 蓝色登录页面2 -->
<template>
  <view class="login">
    <view class="img-a">
      <view class="t-b">
        您好，
        <br/>
        欢迎登录
      </view>
    </view>
    <view class="login-view" style="">
      <view class="t-login">
        <form class="cl">
          <view class="t-a">
            <text class="txt">账号</text>
            <input type="number" name="phone" placeholder="请输入您的账号" maxlength="11" v-model="mobile"/>
          </view>
          <view class="t-a">
            <text class="txt">密码</text>
            <input type="password" name="code" placeholder="请输入您的密码" v-model="password"/>
          </view>
          <button @tap="login()">登 录</button>
        </form>
        <view class="beian">
          仅供公司内部员工使用
        </view>
      </view>
    </view>
  </view>
</template>
<script>
import {storeLogin} from "../../request/api";

export default {
  data() {
    return {
      mobile: '', //手机号码
      password: '', //密码
      checked: false
    };
  },
  onLoad() {
    if (uni.getStorageSync('token')){
      uni.switchTab({
        url:'/pages/index/index'
      })
    }
  },
  methods: {
    //当前登录按钮操作
    login() {
      var that = this;
      if (!this.mobile) {
        uni.showToast({title: '请输入您的手机号', icon: 'none'});
        return;
      }
      // if (!/^[1][3,4,5,7,8,9][0-9]{9}$/.test(that.phone)) {
      // 	uni.showToast({ title: '请输入正确手机号', icon: 'none' });
      // 	return;
      // }
      if (!this.password) {
        uni.showToast({title: '请输入您的密码', icon: 'none'});
        return;
      }
      storeLogin({
        password:this.password,
        mobile:this.mobile,
      }).then(res=>{
        uni.setStorageSync('token',res.data.token);
        uni.setStorageSync('userinfo',res.data.user);
        uni.showToast({
          title:'登录成功',
          icon:'none'
        });
        setTimeout(()=>{
          uni.switchTab({
            url:'/pages/index/index'
          });
        },1000)
      })

    },
    //注册按钮点击
    reg() {
      uni.showToast({title: '注册跳转', icon: 'none'});
    },
    handlePrivacy() {
      uni.navigateTo({
        url: '/pages/webview?src=https://www.xxxx.com/protocol.html'
      })
    },
    // 用户协议
    handleUserAgrement() {
      uni.navigateTo({
        url: '/pages/webview?src=https://www.xxx.com/protocol.html'
      })
    },
    toNav(url) {
      uni.navigateTo({
        url: url
      });
    }
  }
};
</script>
<style>
.login {
  height: 100vh;
  width: 100vw;
  display: flex;
  background-color: #3563FF;
  flex-direction: column;
  justify-content: flex-end;
}

.txt {
  font-size: 32rpx;
  font-weight: bold;
  color: #333333;
}

.img-a {
  margin-bottom: 100rpx;
  width: 100%;
}

.reg {
  font-size: 28rpx;
  color: #fff;
  height: 90rpx;
  line-height: 90rpx;
  border-radius: 50rpx;
  font-weight: bold;
  background: #f5f6fa;
  color: #000000;
  text-align: center;
  margin-top: 30rpx;
}

.xieyi {
  color: #333;
  margin-top: 20px;
  margin-left: 20rpx;
}

.text-blue {
  color: blue;
}


.login-view {
  width: 100%;
  position: relative;
  background-color: #ffffff;
  border-radius: 8% 8% 0% 0;
}

.t-login {
  width: 600rpx;
  margin: 0 auto;
  font-size: 28rpx;
  padding-top: 80rpx;
}

.t-login button {
  font-size: 28rpx;
  background: #3563FF;
  color: #fff;
  height: 90rpx;
  line-height: 90rpx;
  border-radius: 50rpx;
  font-weight: bold;
}

.t-login input {
  height: 90rpx;
  line-height: 90rpx;
  margin-bottom: 50rpx;
  border-bottom: 1px solid #e9e9e9;
  font-size: 28rpx;
}

.t-login .t-a {
  position: relative;
}

.t-b {
  text-align: left;
  font-size: 42rpx;
  color: #fff;
  padding: 50rpx 0 0 70rpx;
  font-weight: bold;
  line-height: 70rpx;
}

.t-login .t-c {
  position: absolute;
  right: 22rpx;
  top: 22rpx;
  background: #5677fc;
  color: #fff;
  font-size: 24rpx;
  border-radius: 50rpx;
  height: 50rpx;
  line-height: 50rpx;
  padding: 0 25rpx;
}

.t-login .t-d {
  text-align: center;
  color: #999;
  margin: 80rpx 0;
}

.t-login .t-e {
  text-align: center;
  width: 250rpx;
  margin: 80rpx auto 0;
}

.t-login .t-g {
  float: left;
  width: 50%;
}

.t-login .t-e image {
  width: 50rpx;
  height: 50rpx;
}

.t-login .t-f {
  text-align: center;
  margin: 80rpx 0 0 0;
  color: #666;
}

.t-login .t-f text {
  margin-left: 20rpx;
  color: #aaaaaa;
  font-size: 27rpx;
}

.t-login .uni-input-placeholder {
  color: #aeaeae;
}

.cl {
  zoom: 1;
}

.cl:after {
  clear: both;
  display: block;
  visibility: hidden;
  height: 0;
  content: '\20';
}

.beian {
  text-align: center;
  color: black;
  font-size: 12px;
  margin-top: 500rpx;
  padding-bottom: 50rpx;
  margin-bottom: 20rpx;
}
</style>
